// pages/test/test.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.request = require('../../common/networks');
    this.util = require('../../common/util');
    // getApp().globalData.localOrderList.push({ orderNo: "391833605379" });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var orderList = wx.getStorageSync("orderList") || [];

    var list = [];
    var expireTime = (new Date()).getTime() - 7 * 24 * 60 * 60 * 1000;
    for (var i = 1; i <= orderList.length && list.length < 5; ++i) {
      var order = orderList[orderList.length - i];
      if (typeof order.createTime == 'string') {
        continue;
      }
      if (order.createTime < expireTime) {
        continue;
      }
      list.push(order);
    }
    this.setData({
      orderList: list
    });
    wx.setStorageSync("orderList", list);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  bindCreateOrder: function(e) {
    wx.navigateTo({
      url: '../../pages/order/order?test=1&name=2',
    })
  },
  bindSearch: function(e) {
    var keyword = this.data.keyword;
    if (this.util.isEmpty(keyword)) {
      this.util.showToast("请输入你要查询的手机号码或者订单号");
      return;
    }
    var isMobile = this.util.isMobile(keyword);
    var isOrderNo = !isMobile && this.util.isOrderNo(keyword);
    if (!isMobile && !isOrderNo) {
      this.util.showToast("请输入正确的手机号码或者订单号");
      return;
    }

    wx.navigateTo({
      url: '../../pages/search/search?keyword=' + keyword,
    })
  },
  bindKeywordInput: function(e) {
    this.data.keyword = e.detail.value;
  },
  bindOrderDetail: function(e) {
    var orderNo = e.currentTarget.dataset.orderNo;
    wx.navigateTo({
      url: '../../pages/detail/detail?orderNo=' + orderNo,
    })
  }
})